package cn.mjnxin.iot.gate.sender;

import cn.mjnxin.iot.base.domain.ChannelData;
import cn.mjnxin.iot.base.domain.SocketData;
import cn.mjnxin.iot.base.util.Direction;
import io.netty.buffer.ByteBuf;

/**
 * 主动发送器
 * @author CLG 2023年10月10日
 * @version V1.0.0
 */
public interface IChannelDataSender {
	void sendChannelData(ChannelData request, Direction direction) throws InterruptedException;
	
	default void sendHost(byte[] outData, Integer pid, String hostAddress) throws InterruptedException {
		SocketData data = new SocketData(outData);
		data.setPid(pid);
		ChannelData response = new ChannelData(pid, data);
		response.setHostAddress(hostAddress);
		
		sendChannelData(response, Direction.RIGHT);
	}
	
	default void sendHost(ByteBuf outData, Integer pid, String hostAddress) throws InterruptedException {
		SocketData data = new SocketData(outData);
		data.setPid(pid);
		ChannelData response = new ChannelData(pid, data);
		response.setHostAddress(hostAddress);
		
		sendChannelData(response, Direction.RIGHT);
	}

	default void sendTerminal(byte[] outData, Integer pid, String terminalAddress) throws InterruptedException {
		SocketData data = new SocketData(outData);
		data.setPid(pid);
		ChannelData response = new ChannelData(pid, data);
		response.setTerminalAddress(terminalAddress);
		
		sendChannelData(response, Direction.LEFT);
	}
	
	default void sendTerminal(ByteBuf outData, Integer pid, String terminalAddress) throws InterruptedException {
		SocketData data = new SocketData(outData);
		data.setPid(pid);
		ChannelData response = new ChannelData(pid, data);
		response.setTerminalAddress(terminalAddress);
		
		sendChannelData(response, Direction.LEFT);
	}
}
